import Vue from 'vue';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css'; // 引入样式
// FIXME(CFY) 使用 script js 引入
// import Router from 'vue-router';

Vue.use(VueRouter);

const router = new VueRouter({
  // TODO 如果要使用 history 模式需要后端一起支持
  // 参考: https://router.vuejs.org/zh/guide/essentials/history-mode.html
  // mode: 'history',
  routes: [
    // 首页
    {
      path: '/',
      redirect: '/loading',
    },
    // loading页面
    {
      path: '/loading',
      name: 'Loading',
      component: resolve => require(['@/views/loading'], resolve),
    },
    {
      path: '/login',
      name: 'Login',
      component: resolve => require(['@/views/login'], resolve),
    },
    {
      path: '/home',
      name: 'Home',
      component: resolve => require(['@/views/home'], resolve),
      meta: {
        keepAlive: false, // 演示如何使用 keepAlive
      },
    },
    {
      path: '/address-book',
      name: 'AddressBook',
      component: resolve => require(['@/views/dood/address-book'], resolve),
    },
    // 通知消息
    {
      path: '/message',
      name: 'Message',
      component: resolve => require(['@/views/message/index'], resolve),
      meta: {
        keepAlive: true,
      },
    },
    // 编辑消息
    {
      path: '/editMessage',
      name: 'EditMessage',
      component: (resolve) => require(['@/views/edit-message/index.vue'], resolve),
      meta: {
        keepAlive: true,
      },
    },
    // 通知详情
    {
      path: '/messageDetail',
      name: 'MessageDetail',
      component: (resolve) => require(['@/views/message-detail/index.vue'], resolve),
    },
    // 设置
    {
      path: '/setting',
      name: 'Setting',
      component: resolve => require(['@/views/setting/setting'], resolve),
    },
    // 文件上传下载
    {
      path: '/file',
      name: 'File',
      component: resolve => require(['@/views/file/index'], resolve),
    },
    // 文件数据流方式下载
    {
      path: '/file/dataflow',
      name: 'DataFlow',
      component: resolve => require(['@/views/file/dataflow'], resolve),
    },
    {
      path: '/file/static-resource',
      name: 'StaticResource',
      component: resolve => require(['@/views/file/static-resource'], resolve),
    },
    // 关于
    {
      path: '/about',
      name: 'About',
      component: resolve =>
        require(['@/views/setting/about'], resolve),
    },
    // jssdk 测试页面
    {
      path: '/jssdk-test',
      name: 'JssdkTest',
      component: resolve => require(['@/views/setting/jssdk-test'], resolve),
    },
    // 客服说明页面
    {
      path: '/customer-service',
      name: 'customerService',
      component: resolve => require(['@/views/customer-service/index'], resolve),
    }
  ],
});

router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
});

router.afterEach(() => {
  NProgress.done();
});

export default router;
